// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
var PlaneEmit = require('./../PlaneEmit');
var UtilGameObject = require('./../../../../../FrameWork/Utils/UtilGameObject');
cc.Class(
{
    extends: PlaneEmit,
    onLoad: function()
    {
        this._super();
    },

    /**
     * _cycleTime:延时周期（单位毫秒）
     */
    doStart: function(_cycleTime, _nodeParent)
    {
        this._super(_cycleTime, _nodeParent);
        this.cycleTime = !!_cycleTime ? _cycleTime : this.getRateRand();
        this.nodeParent = !!_nodeParent ? _nodeParent : this.nodePlane.parent;
        var actArray = [
            cc.delayTime(this.cycleTime * 0.001),
            cc.callFunc(function()
            {
                var newVec2 = this.node.convertToWorldSpaceAR(cc.v2(0, 0));
                var pos = this.nodeParent.convertToNodeSpaceAR(newVec2);
                var nodeBullet = UtilGameObject.createAddparentByPrefabs(this.prefabBullet, this.nodeParent);
                nodeBullet.x = pos.x;
                nodeBullet.y = pos.y;
                this.sendAction(nodeBullet);
            }.bind(this))
        ];
        var seq = cc.sequence(actArray);
        this.node.runAction(cc.repeatForever(seq));
    },

    sendAction(nodeBullet)
    {
        if (!!this.actionBullet && nodeBullet)
        {
            var act = cc.sequence([this.actionBullet.getAction(), cc.callFunc(function()
            {
                nodeBullet.destroy();
            })])
            nodeBullet.runAction(act);
        }
    }
});